package com.yzx.lifeassistants.model.analysis;

import org.json.JSONException;
import org.json.JSONObject;

import com.yzx.lifeassistants.utils.LogcatUtils;

/**
 * @Description: 解析图书续借返回的结果
 * @author: yzx
 * @time: 2016-3-8 上午10:26:44
 */
public class RenewBookAnalysis {

	/**
	 * 
	 * @Description: 因条形码出错而续借失败
	 */
	public static Boolean isError(String response) {
		Boolean isError = true;
		try {
			JSONObject jsonObject = new JSONObject(response);
			if (jsonObject.getBoolean("status")) {
				isError = false;
			} else {
				String errMsg = jsonObject.getString("errMsg");
				LogcatUtils.e("解析图书续借返回的结果失败", errMsg);
				if ("续借失败!已续借过一次".equals(errMsg)) {
					isError = false;
				}
			}
		} catch (JSONException e) {
			if (null != e.getMessage()) {
				LogcatUtils.e("解析图书续借返回的结果异常", e.getMessage());
			}
		}
		return isError;
	}

	/**
	 * 
	 * @Description: 因续借过一次而续借失败
	 */
	public static Boolean alreadyRenew(String response) {
		Boolean alreadyRenew = true;
		try {
			JSONObject jsonObject = new JSONObject(response);
			if (jsonObject.getBoolean("status")) {
				alreadyRenew = false;
			} else {
				String errMsg = jsonObject.getString("errMsg");
				LogcatUtils.e("解析图书续借返回的结果失败", errMsg);
				if (!"续借失败!已续借过一次".equals(errMsg)) {
					alreadyRenew = false;
				}
			}
		} catch (JSONException e) {
			if (null != e.getMessage()) {
				LogcatUtils.e("解析图书续借返回的结果异常", e.getMessage());
			}
		}
		return alreadyRenew;
	}

	/**
	 * 
	 * @Description: 是否续借成功
	 */
	public static Boolean isSuccess(String response) {
		Boolean isSuccess = false;
		try {
			JSONObject jsonObject = new JSONObject(response);
			if (jsonObject.getBoolean("status")) {
				isSuccess = true;
			}
		} catch (JSONException e) {
			if (null != e.getMessage()) {
				LogcatUtils.e("解析图书续借返回的结果异常", e.getMessage());
			}
		}
		return isSuccess;
	}

}
